<div class="x-list-title">
<table width="100%" border="0" height="100%">
	<tr>
		<td align="left">
			<h2>Lịch cá nhân tháng</h2>
		</td>
		<td align="right">	
			<div class="x-list-options">	
				<a href="#Calendar/Index/Add" class="x-button">Lịch cá nhân mới</a>
				<a href="#Calendar/Company/Add" class="x-button">Lịch cơ quan mới</a>
			</div>
		</td>
	</tr>
</table>	
</div>
<div class="calendar-bar-container">
	<div class="calendar-bar">
		<?php $time = $this->get('time');?>
		<?php $pre_date  = date('\y\e\a\r=Y&\m\o\n\t\h=m',strtotime("-1 month",$time));?>
		<?php $next_date = date('\y\e\a\r=Y&\m\o\n\t\h=m',strtotime("+1 month",$time));?>
		<div class="calendar-ctr"><a href="#Calendar/Index/Month?<?php _e($pre_date);?>" class="pre-calendar"></a>
		<a href="#Calendar/Index/Month?<?php _e($next_date);?>" class="next-calendar"></a></div>
		  Tháng <?php _e(date("m",$time))?> năm <?php _e(date("Y",$time))?>
		<?php include "_Options.phtml";?>
	</div>
</div>
<table width="100%" class="x-list x-calendar" cellpadding="0" cellspacing="0">

<?php
	$time  = $this->get("time");
	$year  = $this->get("year");
	$month = $this->get("month");
	
	$firstDay = getdate( mktime(0,0,0,$month,1,$year ));
    $lastDay  = getdate( mktime(0,0,0,$month+1,0,$year ) );
	
?>
<tr class="calendar-month-bar">
	<td class="calendar-day" align="center">Thứ 2</td>
	<td class="calendar-day" align="center">Thứ 3</td>
	<td class="calendar-day" align="center">Thứ 4</td>
	<td class="calendar-day" align="center">Thứ 5</td>
	<td class="calendar-day" align="center">Thứ 6</td>
	<td class="calendar-day" align="center">Thứ 7</td>
	<td class="calendar-day sunday" align="center"><b>CN</b></td>
</tr>
<?php
	function show_calendar_in_date( $ar, $date ){
		foreach( (array)$ar[$date] as $a ){
			$time = date('H:i',strtotime($a['time_start'])).'-'.date('H:i',strtotime($a['time_end']));
			
			$tooltip ="<div class='x-toolbox'>
				<div class='event-quick-box'>
				<div style='border-bottom:1px solid #ddd;padding:0px 0px 5px 0px'>
				<big><b>{$a['title']}</b></big><br/>
				<i>$time</i><br/>
				</div><div style='padding:5px 0px'>
				".short_title(strip_tags($a['content']),300)."
				</div></div>
			</div>";		
			
			_e("<a href='#Calendar/Index/View?ID={$a['ID']}' class='x-tooltip calendar-month-post'>&#187; {$a['title']} $tooltip</a>");
		}
	}
	$ar = $this->get("months");
	$t = ((int)$year)."-".((int)$month)."-";
?>
<?php
	$fday = $firstDay['wday'] == 0 ? 7 : $firstDay['wday'];
    _e('<tr>');
    for($i=1; $i < $fday;$i++){
        _e('<td class="calendar-month-ignore calendar-month">&nbsp;</td>');
    }
    $actday = 0;
    for($i=$fday;$i <= 7;$i++){
        $actday++;
        _e("<td valign='top' align='center' class='calendar-month'>
			<a class='calendar-month-item' href='#Calendar?date=$year-$month-$actday'>$actday</a>");
		show_calendar_in_date($ar,$t.$actday);	
		_e("</td>");
    }
    _e('</tr>');
?> 
<?php
    $fullWeeks = floor(($lastDay['mday']-$actday)/7);
    
    for ($i=0;$i < $fullWeeks;$i++){
        _e('<tr>');
        for ($j=0;$j<7;$j++){
            $actday++;
            _e("<td valign='top' align='center' class='calendar-month'>
				<a class='calendar-month-item' href='#Calendar?date=$year-$month-$actday'>$actday</a>");
			show_calendar_in_date($ar,$t.$actday);	
			_e("</td>");
        }
        _e('</tr>');
    }
?> 
<?php
    if ($actday < $lastDay['mday']){
        _e('<tr>');
        
        for ($i=0; $i<7;$i++){
            $actday++;
            if ($actday <= $lastDay['mday']){
                _e("<td valign='top' align='center' class='calendar-month'>
					<a class='calendar-month-item' href='#Calendar?date=$year-$month-$actday'>$actday</a>");
				show_calendar_in_date($ar,$t.$actday);	
				_e("</td>");
            }
            else {
                _e('<td class="calendar-month-ignore calendar-month">&nbsp;</td>');
            }
        }
        _e('</tr>');
    }
?> 
</table>